/**
 * 合并,不影响原数据,重复的key 会被覆盖
 * @param obj1
 * @param obj2
 */
function appendObj(obj1, obj2) {
	const reObj = {}
	for (const key in obj1) {
		if (obj1[key] != null) {
			reObj[key] = obj1[key]
		}
	}
	if (obj2 !== undefined) {
		for (const key in obj2) {
			if (obj2[key] != null) {
				reObj[key] = obj2[key]
			}
		}
	}
	return reObj
}

// 将一个数组拆分成多个数组
function group(list, length) {
	let index = 0
	let newArray = []
	while (index < list.length) {
		newArray.push(list.slice(index, (index += length)))
	}
	return newArray
}

// 数组转树
function arrayToTree(list, pid) {
	return list.filter(item => pid ? item.parentId === pid : item.parentId === '')
		.map(item => {
			item.children = this.arrayToTree(list, item.id)
			return item
		})
}

// 根据对象内某个属性去重  [{name:'11',value:'aa'},{name:'11',value:'bb'}]
function uniqueByValue(array, key) {
	return array.filter((item, index) => {
		const value = item[key];
		return array.findIndex(i => i[key] === value) === index;
	});
}